<head>
    <style>
        body{
            background: url(http://mymaplist.com/img/parallax/back.png);
            background-color: #444;
            background: url(http://mymaplist.com/img/parallax/pinlayer2.png),url(http://mymaplist.com/img/parallax/pinlayer1.png),url(http://mymaplist.com/img/parallax/back.png);
        }

        .vertical-offset-100{
            padding-top:100px;
        }
    </style>
</head>

<body>

<script src="<?php echo base_url() ?>assets/js/TweenLite.min.js"></script>

<div class="container">
    <div class="row vertical-offset-100">
        <div class="col-md-4 col-md-offset-4">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <button class="btn btn-danger pull-right" onclick="window.history.back();"><span class="glyphicon glyphicon-remove"></span></button>
                    <h3>ĐĂNG NHẬP <?php if($this->session->userdata('linkAdmin') != ''){echo "ADMIN";} ?></h3>
                </div>
                <div class="panel-body">
                    <form accept-charset="UTF-8" role="form" method="post" action="<?php echo base_url() ?>" id="frmLogin">
                        <fieldset>
                            <div class="form-group">
                                <input class="form-control" type="text" name="login" placeholder="Email" required id="login"/>
                            </div>
                            <div class="form-group">
                                <input class="form-control" type="password" name="password" placeholder="Password" required id="password"/>
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input name="remember" type="checkbox" value="Remember Me" id="rememberMe"> Remember Me
                                </label>
                                <label class="pull-right">
                                    <a href="<?php echo base_url() ?>password"><i>Quên mật khẩu</i></a>
                                </label>
                            </div>
                            <div class="alert alert-danger" role="alert" id="reqLogin" style="display: none"></div>
                            <input class="btn btn-lg btn-success btn-block" type="submit" value="Login" id="subLogin">
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function(){
        $(document).mousemove(function(e){
            TweenLite.to($('body'),
                .5,
                { css:
                {
                    backgroundPosition: ""+ parseInt(event.pageX/8) + "px "+parseInt(event.pageY/'12')+"px, "+parseInt(event.pageX/'15')+"px "+parseInt(event.pageY/'15')+"px, "+parseInt(event.pageX/'30')+"px "+parseInt(event.pageY/'30')+"px"
                }
                });
        });
    });

    $('#subLogin').click(function(){
        $('#reqLogin').html('');
        var email = $('#login').val();
        var password = $('#password').val();
        var url = "<?php echo base_url() ?>";
        var remember = 0;
        if($('#rememberMe').is(':checked')){
            remember = 1;
        }
        var dataString = "email="+email+"&password="+password+"&remember="+remember;
//        alert(dataString);
        if(email != '' && password != ''){
            $.ajax({
                type: "POST",
                url: url+"users/checkLogin",
                data: dataString,
                success: function(x){
                    //alert(x);
                    if(x == "000"){
                        $('#reqLogin').css('display', 'block');
                        $('#reqLogin').html('Tài khoản email chưa được đăng ký!');
                    }
                    else{
                        if(x == "00"){
                            $('#reqLogin').css('display', 'block');
                            $('#reqLogin').html("Tài khoản hiện chưa được kích hoạt!");
                        }
                        else{
                            if(x == "0"){
                                $('#reqLogin').css('display', 'block');
                                $('#reqLogin').html("Sai email hoặc mật khẩu!");
                            }
                            else{
//                        $('#frmLogin').submit();
                                var linkAdmin = "<?php echo $this->session->userdata('linkAdmin'); ?>";
//                        alert(linkAdmin)
                                if(linkAdmin == ''){
                                    if(document.referrer = "<?php echo base_url() ?>?reload"){ //set lai khi thay doi controller mac dinh /hotline?reload
                                        window.location.href = "<?php echo base_url() ?>";
                                    }
                                    else{
                                        window.history.back();
                                    }
                                }
                                else{
                                    window.location.href = linkAdmin;
                                }
                            }
                        }
                    }
                }
            });
            return false;
        }
    });
</script>